﻿using System;
using System.Collections.Generic;

//Using TM Namespaces
using ThatsMeSDK;
using ThatsMeSDK.Core;

namespace TMSDKSampleApplication
{
	class Program
	{
		public static void Main(string[] args)
		{
			// This is a sample application to show
			// how the SDK works and how you can use it!
			//
			// We're going to login and get some messages
			// from our mailbox.
			//
			// Writte by cansik / 14.06.2011
			// Release: 0.5.4182.18174 (nightly built)
			Console.WriteLine("TM SDK Example");
			
			//declare some variables
			string username;
			string passwordhash;
			string token;
			
			//Initializing the ServiceHandler Core
			ServiceHandler.Initialize(DataFormat.Xml, true, "test=1");
			
			//Get logindata
			Console.Write("Username: ");
			username = Console.ReadLine();
			Console.Write("Password: ");
			
			//Calculating password into a hash string
			//Please hide it in a "real" application
			passwordhash = ServiceHandler.CalculateMD5(Console.ReadLine());
			
			//Now, try to login
			token = ServiceHandler.Authenticate(username, passwordhash);
			
			//Check if login was OK
			if (token.Equals(string.Empty))
			{
				//If token was Emtpy, write it into the buffer
				Console.WriteLine("login failed!");
			}
			else
			{
				//If token has been set, load messages
				List<Message> messages = ServiceHandler.GetMessages(token, 0, 10, MessageType.Both, true);
				
				//Write them into the buffer:
				foreach(Message m in messages)
				{
					Console.WriteLine(m.Header.From.Nick + " : " + m.Header.Subject);
				}
			}
			
			//Let's wait to see the result!
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
}